package com.ymatou.iapi.dguser.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UpdateUserInfoBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.parameter.UserDto;
import com.ymatou.iapi.dguser.service.UpdateUserInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.utils.TestDataManager;
/**
*更新用户信息Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateUserInfo{
	private static UpdateUserInfoBean updateuserinfoBean;
	private static UpdateUserInfoCall updateuserinfoCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新用户信息Test");
	}

	@Before
	public void caseUp() {
		updateuserinfoBean=new UpdateUserInfoBean();
		updateuserinfoCall=new UpdateUserInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updateuserinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserInfo_001() {
		Logger.start(true,"普通用户修改密码，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			UserDto oldInfo = DGUserCallService.getDGUserInfo(user);
			Logger.verifyEquals(true, DGUserCallService.GetUserByUsernameAndPwd(u.getLoginId(), u.getLoginPwd()), "登录成功");
			updateuserinfoBean.setUserId(user);
			updateuserinfoBean.setLoginPwd("test123");
			updateuserinfoCall.setData(updateuserinfoBean);
			updateuserinfoCall.callService();			
			Logger.verifyEquals("true", updateuserinfoCall.getString("success"), "验证code");
			UserDto newInfo = DGUserCallService.getDGUserInfo(user);
			Logger.verifyEquals(true, DGUserCallService.GetUserByUsernameAndPwd(u.getLoginId(), "test123"), "使用新密码登录成功");
			Logger.verifyEquals(false, DGUserCallService.GetUserByUsernameAndPwd(u.getLoginId(), u.getLoginPwd()), "使用旧密码登录失败");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserInfo_002() {
		Logger.start(true,"普通用户修改手机号，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			int user = DGUserCallService.UserCreateCall(u);
			String phoneNum = TestDataManager.getPhoneNum();
			UserDto oldInfo = DGUserCallService.getDGUserInfo(user);
			updateuserinfoBean.setUserId(user);
			updateuserinfoBean.setMobile(phoneNum);
			updateuserinfoCall.setData(updateuserinfoBean);
			updateuserinfoCall.callService();			
			Logger.verifyEquals("true", updateuserinfoCall.getString("success"), "验证code");
			UserDto newInfo = DGUserCallService.getDGUserInfo(user);
			Logger.verifyNotEquals(oldInfo.getMobile(), newInfo.getMobile(), "判断两次的手机号不同");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserInfo_003() {
		Logger.start(true,"普通用户修改区号，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			int user = DGUserCallService.UserCreateCall(u);
			UserDto oldInfo = DGUserCallService.getDGUserInfo(user);
			updateuserinfoBean.setUserId(user);
			updateuserinfoBean.setMobileAreaCode("1");
			updateuserinfoCall.setData(updateuserinfoBean);
			updateuserinfoCall.callService();			
			Logger.verifyEquals("true", updateuserinfoCall.getString("success"), "验证code");
			UserDto newInfo = DGUserCallService.getDGUserInfo(user);
			Logger.verifyNotEquals(oldInfo.getMobileAreaCode(), newInfo.getMobileAreaCode(), "判断两次的手机区号不同");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserInfo_004() {
		Logger.start(true,"普通用户修改手机号与区号，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			int user = DGUserCallService.UserCreateCall(u);
			String phoneNum = TestDataManager.getPhoneNum();
			UserDto oldInfo = DGUserCallService.getDGUserInfo(user);
			updateuserinfoBean.setUserId(user);
			updateuserinfoBean.setMobile(phoneNum);
			updateuserinfoBean.setMobileAreaCode("1");
			updateuserinfoCall.setData(updateuserinfoBean);
			updateuserinfoCall.callService();			
			Logger.verifyEquals("true", updateuserinfoCall.getString("success"), "验证code");
			UserDto newInfo = DGUserCallService.getDGUserInfo(user);
			Logger.verifyNotEquals(oldInfo.getMobile(), newInfo.getMobile(), "判断两次的手机号不同");
			Logger.verifyNotEquals(oldInfo.getMobileAreaCode(), newInfo.getMobileAreaCode(), "判断两次的手机区号不同");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserInfo_005() {
		Logger.start(true,"普通用户修改手机号与区号，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			int user = DGUserCallService.UserCreateCall(u);
			String phoneNum = TestDataManager.getPhoneNum();
			UserDto oldInfo = DGUserCallService.getDGUserInfo(user);
			updateuserinfoBean.setUserId(user);
			updateuserinfoBean.setMobile(phoneNum);
			updateuserinfoBean.setMobileAreaCode("1");
			updateuserinfoCall.setData(updateuserinfoBean);
			updateuserinfoCall.callService();			
			Logger.verifyEquals("true", updateuserinfoCall.getString("success"), "验证code");
			UserDto newInfo = DGUserCallService.getDGUserInfo(user);
			Logger.verifyNotEquals(oldInfo.getMobile(), newInfo.getMobile(), "判断两次的手机号不同");
			Logger.verifyNotEquals(oldInfo.getMobileAreaCode(), newInfo.getMobileAreaCode(), "判断两次的手机区号不同");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserInfo_006() {
		Logger.start(true,"普通用户修改登录账号，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			UserDto oldInfo = DGUserCallService.getDGUserInfo(user);
			updateuserinfoBean.setUserId(user);
			updateuserinfoBean.setLoginId("user"+u.getLoginId());
			updateuserinfoCall.setData(updateuserinfoBean);
			updateuserinfoCall.callService();			
			Logger.verifyEquals("true", updateuserinfoCall.getString("success"), "验证code");
			UserDto newInfo = DGUserCallService.getDGUserInfo(user);
			Logger.verifyNotEquals(oldInfo.getLoginId(), newInfo.getLoginId(), "判断两次的手机区号不同");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserInfo_007() {
		Logger.start(true,"只传入userid，失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			updateuserinfoBean.setUserId(user);
			updateuserinfoCall.setData(updateuserinfoBean);
			updateuserinfoCall.callService();			
			Logger.verifyEquals("false", updateuserinfoCall.getString("success"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserInfo_008() {
		Logger.start(true,"传入密码为空，失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			updateuserinfoBean.setUserId(user);
			updateuserinfoBean.setLoginPwd("");
			updateuserinfoCall.setData(updateuserinfoBean);
			updateuserinfoCall.callService();			
			Logger.verifyEquals("false", updateuserinfoCall.getString("success"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserInfo_009() {
		Logger.start(true,"传入手机号为空，失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			updateuserinfoBean.setUserId(user);
			updateuserinfoBean.setMobile("");
			updateuserinfoCall.setData(updateuserinfoBean);
			updateuserinfoCall.callService();			
			Logger.verifyEquals("false", updateuserinfoCall.getString("success"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserInfo_010() {
		Logger.start(true,"普通用户修改所有信息，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			int user = DGUserCallService.UserCreateCall(u);
			String phoneNum = TestDataManager.getPhoneNum();
			UserDto oldInfo = DGUserCallService.getDGUserInfo(user);
			updateuserinfoBean.setUserId(user);
			updateuserinfoBean.setMobile(phoneNum);
			updateuserinfoBean.setMobileAreaCode("1");
			updateuserinfoBean.setLoginPwd("a12313");
			updateuserinfoBean.setLoginId("user"+u.getLoginId());
			updateuserinfoCall.setData(updateuserinfoBean);
			updateuserinfoCall.callService();			
			Logger.verifyEquals("true", updateuserinfoCall.getString("success"), "验证code");
			UserDto newInfo = DGUserCallService.getDGUserInfo(user);
			Logger.verifyNotEquals(oldInfo.getMobile(), newInfo.getMobile(), "判断两次的手机号不同");
			Logger.verifyNotEquals(oldInfo.getMobileAreaCode(), newInfo.getMobileAreaCode(), "判断两次的手机区号不同");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserInfo_011() {
		Logger.start(true,"普通用户修改手机号，手机号重复失败");
		try {
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean u1 = DGUserCallService.initUsercreateBean();
			u1.setMobile(mobile);
			u1.setMobileAreaCode("86");
			DGUserCallService.UserCreateCall(u1);
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			int user = DGUserCallService.UserCreateCall(u);
			updateuserinfoBean.setUserId(user);
			updateuserinfoBean.setMobile(mobile);
			updateuserinfoCall.setData(updateuserinfoBean);
			updateuserinfoCall.callService();			
			Logger.verifyEquals("false", updateuserinfoCall.getString("success"), "验证code");
			Logger.verifyEquals("手机号已被其它用户绑定", updateuserinfoCall.getString("errorMessage"), "验证errorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}